#pragma once

#include "BasicEvent.h"
#include <winsock2.h>
#include "XString.h"

namespace events {

class NetworkEvent : public BasicEvent
{
public:
	enum NetworkEventType {
		NE_CREATE_SOCKET,
		NE_CONNECT,
		NE_LISTEN,
		NE_SEND,
		NE_SEND_TO,
		NE_RECEIVE,
		NE_RECEIVE_FROM,
		NE_GET_HOST_BY_NAME
	};

public:
	inline NetworkEvent(void)
		: BasicEvent(BasicEvent::EVENT_NETWORK),
		  _netype(NE_CREATE_SOCKET),
		  _s((SOCKET)0),
		  _ip((unsigned long)0)
	{}

	inline NetworkEvent(NetworkEventType type, SOCKET s)
		: BasicEvent(BasicEvent::EVENT_NETWORK),
		  _netype(type),
		  _s(s),
		  _ip((unsigned long)0)
	{}

	inline void setHost(const platform::XString& host) { _host = host; }
	inline void setIp(unsigned long ip) { _ip = ip; }

	virtual ~NetworkEvent(void) {}

	// getters
	inline NetworkEventType getType(void) const { return _netype; }
	inline SOCKET getSocket(void) const { return _s(); }
	inline const platform::XString & getHost(void) const { return _host; }

	// implementing ISerializable
public:
	virtual void saveToStream(std::ostream &os) const;
	virtual void readFromStream(std::istream &is);
	virtual void writeDebugInfo(std::ostream &os) const;


private:
	// helpers
	inline void writeIp(std::ostream &os) const;

private:
	NetworkEventType _netype;
	GenericDataType<SOCKET> _s;
	platform::XString _host;
	GenericDataType<unsigned long> _ip;
};


}  // end namespace
